{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 02 Valid discrete probability distribution examples"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
""
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from pandas import Series, DataFrame\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[khanacademy](https://www.khanacademy.org/math/ap-statistics/random-variables-ap/discrete-random-variables/v/valid-discrete-probability-distribution-examples?modal=1)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"basketball_df = DataFrame({'Outcome': ['Miss both free throws', 'Make exactly one free throw', 'Make both free throws'],\n",
" 'Probabilty': [0.2, 0.5, 0.1]}).set_index('Outcome')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Probabilty | \n",
"
\n",
" \n",
" Outcome | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" Miss both free throws | \n",
" 0.2 | \n",
"
\n",
" \n",
" Make exactly one free throw | \n",
" 0.5 | \n",
"
\n",
" \n",
" Make both free throws | \n",
" 0.1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Probabilty\n",
"Outcome \n",
"Miss both free throws 0.2\n",
"Make exactly one free throw 0.5\n",
"Make both free throws 0.1"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"basketball_df"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"basketball_df['Probabilty'].sum() == 1"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"creatures_df = DataFrame({'Type of Earth Creature': ['Chickens', 'Cows', 'Humans'], '#': [97, 47, 77]}).set_index('Type of Earth Creature')"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" # | \n",
"
\n",
" \n",
" Type of Earth Creature | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" Chickens | \n",
" 97 | \n",
"
\n",
" \n",
" Cows | \n",
" 47 | \n",
"
\n",
" \n",
" Humans | \n",
" 77 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" #\n",
"Type of Earth Creature \n",
"Chickens 97\n",
"Cows 47\n",
"Humans 77"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"creatures_df"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"creatures_df['Estimated Probabilty'] = creatures_df['#'] / creatures_df['#'].sum()"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"creatures_df = creatures_df[['Estimated Probabilty']]"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Estimated Probabilty | \n",
"
\n",
" \n",
" Type of Earth Creature | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" Chickens | \n",
" 0.438914 | \n",
"
\n",
" \n",
" Cows | \n",
" 0.212670 | \n",
"
\n",
" \n",
" Humans | \n",
" 0.348416 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Estimated Probabilty\n",
"Type of Earth Creature \n",
"Chickens 0.438914\n",
"Cows 0.212670\n",
"Humans 0.348416"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"creatures_df"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"creatures_df['Estimated Probabilty'].sum() == 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}